/**
 * 
 */
package com.base.myproject.client.ui.codenamemap;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.base.myproject.client.busi.BaseStore;
import com.base.myproject.client.busi.BO.BusiObject;
import com.base.myproject.client.jdbc.StoreInfo;
import com.base.myproject.client.tools.Debug;
import com.base.myproject.client.ui.celleditor.BaseComboBoxForm;
import com.base.myproject.client.ui.celleditor.BaseGridEditor;
import com.extjs.gxt.ui.client.data.BaseModelData;
import com.extjs.gxt.ui.client.data.ModelType;
import com.extjs.gxt.ui.client.util.BaseEventPreview;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.google.gwt.user.client.Element;

/**
 * 常用的码名映射
 * @author zgw
 *2009-10-22 下午04:01:39
 * javazgw@gmail.com
 */
public class CodeNameMapFactory {

	BaseStore<BaseModelData> basebcodestore;
	static BaseStore<BaseModelData> baseccodestore;
	static BaseStore<BaseModelData> basegroupstore;
	static BaseStore<BaseModelData> basegroupstore_filter;
	static BaseStore<BaseModelData> baseSysteminfostore;
	
	public CodeNameMapFactory()
	{
		
	}
	public CodeNameMap initBcodeCodeNameMap()
	{
		CodeNameMap cnm = new CodeNameMap();
		cnm.setLoadSql("select bcode,bname from bcode");
		cnm.load();
		return cnm;
	}
	//-----------------------------------
	/**
	 * Form方式下面的性别辅助录入，有码名映射，类型是 integer
	 */
	static public BaseComboBoxForm<BaseModelData> createSexInput_F()
	{
		
		BaseStore<BusiObject> basestore = new BaseStore<BusiObject>();
		HashMap hm = new HashMap();
		hm.put("code", new Integer("1"));
		hm.put("name", "女");
		BusiObject modeldata = new BusiObject(hm);
		basestore.add(modeldata,false,false);
		hm.put("code", new Integer("2"));
		hm.put("name", "男");
		modeldata = new BusiObject(hm);
		basestore.add(modeldata,false,false);
		BaseComboBoxForm<BaseModelData> bcbf = new BaseComboBoxForm(basestore);
		return bcbf;
	}
	
	/**
	 * Form方式下面的组辅助录入，有码名映射，类型是 integer
	 */
	static public BaseComboBoxForm<BaseModelData> createGroupInput_F()
	{
		
		if(basegroupstore==null)
		{
			ModelType type = new ModelType();
			type.setRoot("records");
			type.setRecordName("record");
			type.setTotalName("totle");
			type.addField("code");
			type.addField("name");
			StoreInfo info = new StoreInfo();
			info.setTablename("bcode");
			info.setNeedAllRow("no");
			info.setSql("select groupicode as code	,groupname as name from basegroup  where groupicode != '999'");
			basegroupstore = new BaseStore<BaseModelData>(type,info);
		}
		BaseComboBoxForm<BaseModelData> bcbf = new BaseComboBoxForm(basegroupstore);
		return bcbf;
	}
	/**
	 * Form方式下面的组辅助录入，有码名映射，类型是 integer
	 * 排除老板
	 */
	static public BaseComboBoxForm<BaseModelData> createGroupInput_F_filter()
	{
		
		if(basegroupstore_filter==null)
		{
			ModelType type = new ModelType();
			type.setRoot("records");
			type.setRecordName("record");
			type.setTotalName("totle");
			type.addField("code");
			type.addField("name");
			StoreInfo info = new StoreInfo();
			info.setTablename("bcode");
			info.setNeedAllRow("no");
			info.setSql("select groupicode as code	,groupname as name from basegroup  where groupicode not in('990','980','300') and groupname is not null");
			basegroupstore_filter = new BaseStore<BaseModelData>(type,info);
		}
		BaseComboBoxForm<BaseModelData> bcbf = new BaseComboBoxForm(basegroupstore_filter);
		return bcbf;
	}
	/**
	 * bcode 的form显示方式
	 * @return
	 */
	public BaseComboBoxForm<BaseModelData>  createBocdeInput_F()
	{
	
		basebcodestore = getBasebcodestore();
		BaseComboBoxForm<BaseModelData> bcbf = new BaseComboBoxForm(basebcodestore);
		return bcbf;
	}
	
	
	/**
	 * Systeminfo 的form显示方式
	 * @return
	 */
	public static BaseComboBoxForm<BaseModelData>  createSysteminfoInput_F()
	{
	
		baseSysteminfostore = getBaseSysteminfostore();
		BaseComboBoxForm<BaseModelData> bcbf = new BaseComboBoxForm<BaseModelData>(baseSysteminfostore);
		return bcbf;
	}
	
	//---------------------------------
	static public BaseGridEditor<String> createSexInput_G()
	{

		
		BaseStore<BusiObject> basestore = new BaseStore<BusiObject>();
		HashMap hm = new HashMap();
		hm.put("sexcode", "1");
		hm.put("sexname", "女");
		BusiObject modeldata = new BusiObject(hm);
		basestore.add(modeldata,false,false);
		hm.put("sexcode", "2");
		hm.put("sexname", "男");
		modeldata = new BusiObject(hm);
		basestore.add(modeldata,false,false);
		
		List<ColumnConfig> bocodecolumns2 = new ArrayList<ColumnConfig>();
		ColumnConfig bcode2 = new ColumnConfig("sexcode", "代码", 100);

		bocodecolumns2.add(bcode2);

		ColumnConfig bname = new ColumnConfig("sexname", "性别", 50);

		bocodecolumns2.add(bname);
		BaseGridEditor<String> bge = new BaseGridEditor<String>(bocodecolumns2,basestore,"sexname")
		{
			@Override
			protected void onRender(Element target, int index) {
				super.onRender(target, index);
				focusPreview = new BaseEventPreview();

				Debug.printf("---debug", 4);
			}
		}
		;
		return bge;
	}
	/**
	 * @return the basestore
	 */
	public BaseStore<BaseModelData> getBasebcodestore() {
		
		if(basebcodestore==null)
		{
			ModelType type = new ModelType();
			type.setRoot("records");
			type.setRecordName("record");
			type.setTotalName("totle");
			type.addField("code");
			type.addField("name");
			StoreInfo info = new StoreInfo();
			info.setTablename("bcode");
			info.setNeedAllRow("no");
			info.setSql("select bcode as code ,bname as name from bcode where bcode is not null and bname is not null");
			basebcodestore = new BaseStore<BaseModelData>(type,info);
		}
		return basebcodestore;
	}
	
	
	public BaseStore<BaseModelData> getBasebcodestore_canaddfinance() {
		
		//if(basebcodestore==null)
		//{
			ModelType type = new ModelType();
			type.setRoot("records");
			type.setRecordName("record");
			type.setTotalName("totle");
			type.addField("code");
			type.addField("name");
			StoreInfo info = new StoreInfo();
			info.setTablename("bcode");
			info.setNeedAllRow("no");
			info.setSql("select bcode as code ,bname as name from bcode where bcode is not null and bname is not null and canaddfinance=1");
			BaseStore<BaseModelData>	basebcodestorefilter_canaddfinance = new BaseStore<BaseModelData>(type,info);
		//}
		return basebcodestorefilter_canaddfinance;
	}
	
	/**
	 * 可以修改单据的人员
	 * @return
	 */
	public BaseStore<BaseModelData> getBasebcodestore_canChangePO() {
		
		//if(basebcodestore==null)
		//{
			ModelType type = new ModelType();
			type.setRoot("records");
			type.setRecordName("record");
			type.setTotalName("totle");
			type.addField("code");
			type.addField("name");
			StoreInfo info = new StoreInfo();
			info.setTablename("bcode");
			info.setNeedAllRow("no");
			info.setSql("select bcode as code ,bname as name from bcode where bcode is not null and bname is not null and canchangepo=1");
			BaseStore<BaseModelData>	basebcodestorefilter_canachangepo = new BaseStore<BaseModelData>(type,info);
		//}
		return basebcodestorefilter_canachangepo;
	}
	/**
	 * 
	 * @return
	 */
	public static  BaseStore<BaseModelData> getBaseSysteminfostore() {
		
		if(baseSysteminfostore==null)
		{
			ModelType type = new ModelType();
			type.setRoot("records");
			type.setRecordName("record");
			type.setTotalName("totle");
			type.addField("code");
			type.addField("name");
			StoreInfo info = new StoreInfo();
			info.setNeedAllRow("no");
			info.setTablename("bcode");
			
			info.setSql("select id as code ,id%2B':'%2Bname as name from SystemInfo where name is not null and id is not null");
			baseSysteminfostore = new BaseStore<BaseModelData>(type,info);
		}
		return baseSysteminfostore;
	}
	/**
	 * @param basestore the basestore to set
	 */
	public void setBasebcodestore(BaseStore<BaseModelData> basestore) {
		this.basebcodestore = basestore;
	}
	/**
	 * @return the baseccodestore
	 */
	public static BaseStore<BaseModelData> getBaseccodestore() {
		
		if(baseccodestore==null)
		{
			ModelType type = new ModelType();
			type.setRoot("records");
			type.setRecordName("record");
			type.setTotalName("totle");
			type.addField("code");
			type.addField("name");
			type.addField("s_cardno");
			StoreInfo info = new StoreInfo();
			info.setTablename("ccode");
			info.setSql("select ccode as code ,cname as name,s_cardno from ccode where ccode is not null and cname is not null");
			baseccodestore = new BaseStore<BaseModelData>(type,info);
		}
		return baseccodestore;
	}
	/**
	 * @param baseccodestore the baseccodestore to set
	 */
	public void setBaseccodestore(BaseStore<BaseModelData> baseccodestore) {
		this.baseccodestore = baseccodestore;
	}
	
	
	
	static BaseStore<BaseModelData>	basebcodestorefilter_all = null;

	static public BaseStore<BaseModelData> loadBcode_ALL()
	{
		if(basebcodestorefilter_all==null)
		{
			ModelType type = new ModelType();
			type.setRoot("records");
			type.setRecordName("record");
			type.setTotalName("totle");
			type.addField("code");
			type.addField("name");
			StoreInfo info = new StoreInfo();
			info.setTablename("bcode");
			info.setNeedAllRow("no");
			info.setForcenolimit("true");
			info.setSql("select bcode as code ,bname as name from bcode where bcode is not null and bname is not null ");
			basebcodestorefilter_all = new BaseStore<BaseModelData>(type,info);
		}
		return basebcodestorefilter_all;
	}
/**
 * 发型师  group =800
 * @return
 */
	static BaseStore<BaseModelData>	basebcodestorefilter_800 = null;

	static public BaseStore<BaseModelData> loadBcode_800()
	{
		if(basebcodestorefilter_800==null)
		{
			ModelType type = new ModelType();
			type.setRoot("records");
			type.setRecordName("record");
			type.setTotalName("totle");
			type.addField("code");
			type.addField("name");
			StoreInfo info = new StoreInfo();
			info.setTablename("bcode");
			info.setNeedAllRow("no");
			info.setSql("select bcode as code ,bname as name from bcode where bcode is not null and bname is not null and  groupicode=800");
			basebcodestorefilter_800 = new BaseStore<BaseModelData>(type,info);
		}
		return basebcodestorefilter_800;
	}
	
	/**
	 * Form方式下面的组辅助录入，有码名映射，类型是 integer
	 */
	static public BaseComboBoxForm<BaseModelData> createfaxingshiInput_F()
	{
		
		
		BaseComboBoxForm<BaseModelData> bcbf = new BaseComboBoxForm(loadBcode_800());
		return bcbf;
	}
	
	
	/**
	 * 技师的store，只做一次载入 801
	 */
	static BaseStore<BaseModelData>	basebcodestorefilter_801 = null;

	static public BaseStore<BaseModelData> loadBcode_801()
	{
		if(basebcodestorefilter_801==null)
		{
			ModelType type = new ModelType();
			type.setRoot("records");
			type.setRecordName("record");
			type.setTotalName("totle");
			type.addField("code");
			type.addField("name");
			StoreInfo info = new StoreInfo();
			info.setTablename("bcode");
			info.setNeedAllRow("no");
			info.setSql("select bcode as code ,bname as name from bcode where bcode is not null and bname is not null and  groupicode=801");
			basebcodestorefilter_801 = new BaseStore<BaseModelData>(type,info);
		}
		return basebcodestorefilter_801;
	}
	
	/**
	 * 技师B的store，只做一次载入 802
	 */
	static BaseStore<BaseModelData>	basebcodestorefilter_802 = null;

	static public BaseStore<BaseModelData> loadBcode_802()
	{
		if(basebcodestorefilter_802==null)
		{
			ModelType type = new ModelType();
			type.setRoot("records");
			type.setRecordName("record");
			type.setTotalName("totle");
			type.addField("code");
			type.addField("name");
			StoreInfo info = new StoreInfo();
			info.setTablename("bcode");
			info.setNeedAllRow("no");
			info.setSql("select bcode as code ,bname as name from bcode where bcode is not null and bname is not null and  groupicode=802");
			basebcodestorefilter_802 = new BaseStore<BaseModelData>(type,info);
		}
		return basebcodestorefilter_802;
	}
	
	
	/**
	 * 助理的store，只做一次载入810
	 */
	static BaseStore<BaseModelData>	basebcodestorefilter_810 = null;

	static public BaseStore<BaseModelData> loadBcode_810()
	{
		if(basebcodestorefilter_810==null)
		{
			ModelType type = new ModelType();
			type.setRoot("records");
			type.setRecordName("record");
			type.setTotalName("totle");
			type.addField("code");
			type.addField("name");
			StoreInfo info = new StoreInfo();
			info.setTablename("bcode");
			info.setNeedAllRow("no");
			info.setSql("select bcode as code ,bname as name from bcode where bcode is not null and bname is not null and  groupicode=810");
			basebcodestorefilter_810 = new BaseStore<BaseModelData>(type,info);
		}
		return basebcodestorefilter_810;
	}
	
	
	/**
	 * 助理的store，只做一次载入810
	 */
	static BaseStore<BaseModelData>	basebcodestorefilter_900 = null;

	static public BaseStore<BaseModelData> loadBcode_900()
	{
		if(basebcodestorefilter_900==null)
		{
			ModelType type = new ModelType();
			type.setRoot("records");
			type.setRecordName("record");
			type.setTotalName("totle");
			type.addField("code");
			type.addField("name");
			StoreInfo info = new StoreInfo();
			info.setTablename("bcode");
			info.setNeedAllRow("no");
			info.setSql("select bcode as code ,bname as name from bcode where bcode is not null and bname is not null and  groupicode=900");
			basebcodestorefilter_900 = new BaseStore<BaseModelData>(type,info);
		}
		return basebcodestorefilter_900;
	}
	
	/**
	 * 轮牌指定的store
	 */
	static BaseStore<BaseModelData>	basemethod = null;
	
	static public BaseStore<BaseModelData>	 getBaseMethodStore()
	{
		if(basemethod==null)
		{
			basemethod = new BaseStore<BaseModelData>();
			HashMap hm = new HashMap();
			hm.put("code", "轮牌");
			hm.put("name", "轮牌");
			BusiObject modeldata = new BusiObject(hm);
			basemethod.add(modeldata, false, false);
			hm.put("code", "指定");
			hm.put("name", "指定");
			modeldata = new BusiObject(hm);
			basemethod.add(modeldata, false, false);
		}
		return basemethod;
	}
}

